<template>
	<view class="container">
		<view class="form">
			<view class="form-item">
				<view class="label">Avatar</view>
				<view class="content">
					<image src="../../static/images/default-avatar.png" mode="" class="avatar" v-if="!userInfo.sysUser.userId">
					</image>
					<image :src="userInfo.sysUser.avatar | formatFile" mode="" class="avatar" v-if="userInfo.sysUser.userId">
					</image>
				</view>
			</view>
			<view class="form-item">
				<view class="label">Teacher name</view>
				<view class="content">
					<text>{{userInfo.sysUser.nickName || ''}}</text>
				</view>
			</view>
			<view class="form-item">
				<view class="label">Account</view>
				<view class="content">
					<text>{{userInfo.sysUser.userName}}</text>
				</view>
			</view>
			<view class="form-item">
				<view class="label">Classify</view>
				<view class="content">
					<text>{{userInfo.tagName}}</text>
				</view>
			</view>
		</view>

		<view class="title">Personal introduction</view>
		<view class="intro-wrapper">{{userInfo.intro}}</view>

		<view class="title">Video introduction</view>
		<video :src="userInfo.videoUrl" controls class="video" :autoplay="false"></video>

		<view class="submit-btn" @tap="showLogout">Sign out</view>

		<my-modal ref="modal"></my-modal>
	</view>
</template>

<script>
	import {
		getTeacherInfo
	} from '@/api/user.js'
	export default {
		data() {
			return {
				userInfo: {
					sysUser: {}
				},
			};
		},
		onShow() {
			this.getTeacherInfo()
		},
		methods: {
			getTeacherInfo() {
				getTeacherInfo().then(res => {
					this.userInfo = res.data
				})
			},
			showLogout() {
				this.$refs.modal.open({
					content: 'Do you want to log out?',
					success: () => {
						this.$store.commit('user/SET_LOGIN', false);
						this.$store.commit('user/SET_TOKEN', "");
						uni.reLaunch({
							url: '/pages/login/login'
						})
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	.container {
		background: #F3F3F3;
		padding-top: 1rpx;

		.form {
			margin-top: 30rpx;

			.avatar {
				width: 68rpx;
				height: 68rpx;
				border-radius: 50%;
			}

		}

		.title {
			padding: 30rpx;
			font-size: 30rpx;
			font-weight: 500;
			color: #666666;
		}

		.intro-wrapper {
			background: #FFFFFF;
			border-radius: 26rpx;
			margin: 0 30rpx;
			padding: 50rpx 30rpx;
			font-size: 28rpx;
			font-family: PingFang SC;
			font-weight: 500;
			color: #333333;
			line-height: 44rpx;
			white-space: pre-line;
		}

		.video {
			width: calc(100% - 60rpx);
			margin: 0 30rpx;

			height: 380rpx;
		}
	}

	.submit-btn {
		margin: 30rpx;
		background-color: #EC1328;
	}
</style>